﻿using GPSTracker.Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace GPSTracker.CommonDAL
{
    public class AttributeDAL
    {
        public static DataTable GetAttributeByType(string type, string name)
        {
            try
            {
                var dt = new DataTable();
                var cmd = new SqlCommand();
                cmd.Connection = CommonFx.GetSqlCon();
                cmd.CommandType = CommandType.Text;

                cmd.CommandText = "SELECT  AttributeID, Type, Name, Value FROM dbo.M_Attribute WHERE Type = @pType AND Name= @pName AND ISNULL(IsActive,0)=1 ORDER BY OrderNo";

                cmd.Parameters.Add(new SqlParameter("@pType", type));
                cmd.Parameters.Add(new SqlParameter("@pName", name));

                var da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                da.Fill(dt);

                return dt;
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(null, typeof(Page), "alertmessage", "javascript:alert('" + Helper.ExceptionHandler.GetErrorMsg(ex) + "');", true);
                return null;
            }
        }
    }
}